//*************************************************************************************
//* 作    者： zouhunter
//* 创建时间： 2021-11-10 12:35:10
//* 描    述： 延迟显示场景

//* ************************************************************************************
using UnityEngine;
using UFrame.SceneLoad;

public class DelyAsyncScene<T>:AsyncGameScene<T> where T : AsyncGameScene<T>
{
    protected float m_loadingStartTime;

    public override void OnEnter(int sceneId, bool alone)
    {
        base.OnEnter(sceneId, alone);
        m_loadingStartTime = Time.time;
    }

    public override void OnEntry(int sceneId)
    {
        base.OnEntry(sceneId);
        m_loadingStartTime = Time.time;
    }

    protected void SceneLoadingDelyExecute(int delyTime,System.Action onOpen = null)
    {
        var timeLeft = delyTime - (Time.time - m_loadingStartTime);
        if (timeLeft > 0.2f)
        {
            TimerAgent.Instance.DelyExecute((System.Action)(() =>
            {
                onOpen?.Invoke();
            }), timeLeft);
        }
        else
        {
            onOpen?.Invoke();
        }
    }
}
